package com.ljh.myaiagent.tools;

import org.springframework.ai.tool.ToolCallback;
import org.springframework.ai.tool.ToolCallbacks;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ToolRegistration {
    @Value("${search-api.api-key}")    // 2.依赖注入模式
    private String searchApiKey;
    @Value("${my-ai-agent.email.from}")
    private String FROM_EMAIL;
    @Value("${my-ai-agent.email.auth-code}")
    private String AUTH_CODE;

    /**
     * 符合 1、工厂模式
     * 2、依赖注入模式
     * 3、注册模式
     * 4、适配器模式的应用
     * @return
     */

    @Bean
    public ToolCallback[] allTools() {
        FileOperationTool fileOperationTool = new FileOperationTool();
        WebSearchTool webSearchTool = new WebSearchTool(searchApiKey);
        WebScrapingTool webScrapingTool = new WebScrapingTool();
        ResourceDownloadTool resourceDownloadTool = new ResourceDownloadTool();
        TerminalOperationTool terminalOperationTool = new TerminalOperationTool();
        PDFGenerationTool pdfGenerationTool = new PDFGenerationTool();
        SendQQEmailTool sendQQEmailTool = new SendQQEmailTool(FROM_EMAIL, AUTH_CODE);
        TerminateTool terminateTool = new TerminateTool();
        return ToolCallbacks.from(  // 4.适配器模式的应用
                fileOperationTool,
                webSearchTool,
                webScrapingTool,
                resourceDownloadTool,
                terminalOperationTool,
                pdfGenerationTool,
                sendQQEmailTool,
                terminateTool
        );
    }
}
